﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PeteBrown.ConferenceTrivia.ViewModels;

namespace PeteBrown.ConferenceTrivia
{
    public partial class MainPage : UserControl
    {
        private MainViewModel _vm;

        public MainPage()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(MainPage_Loaded);
            TriviaQuestionsAndAnswers.NextQuestion += new EventHandler(TriviaQuestionsAndAnswers_NextQuestion);
            App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
        }

        void Content_FullScreenChanged(object sender, EventArgs e)
        {
            if (App.Current.Host.Content.IsFullScreen)
            {
                RunningContent.Visibility = Visibility.Visible;
                OpeningContent.Visibility = Visibility.Collapsed;
            }
            else
            {
                RunningContent.Visibility = Visibility.Collapsed;
                OpeningContent.Visibility = Visibility.Visible;
            }
        }

        void TriviaQuestionsAndAnswers_NextQuestion(object sender, EventArgs e)
        {
            _vm.MoveNext();
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            _vm = new MainViewModel();
            _vm.TriviaLoaded += new EventHandler(OnTriviaLoaded);
            DataContext = _vm;
        }

        void OnTriviaLoaded(object sender, EventArgs e)
        {
            TriviaQuestionsAndAnswers.StartQuestions();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Host.Content.IsFullScreen = true;
        }
    }
}
